package com.heima.comment.controller;


import com.heima.comment.service.ApCommentService;
import com.heima.model.common.dtos.CommentLikeDto;
import com.heima.model.common.dtos.CommentSaveDto;
import com.heima.model.common.dtos.ResponseResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 文章评论
 */
@RestController
@RequestMapping("/api/v1/comment")
@Slf4j
public class ApCommentController {
    @Autowired
    private ApCommentService commentService;

    /**
     * 保存评论
     *
     * @param commentSaveDto
     * @return
     */
    @PostMapping("/save")
    public ResponseResult save(@RequestBody CommentSaveDto commentSaveDto){
        log.info("保存文章评论：{}",commentSaveDto);
        return commentService.save(commentSaveDto);
    }

    /**
     * 查看评论列表
     *
     * @param commentSaveDto
     * @return
     */
    @PostMapping("/load")
    public ResponseResult load(@RequestBody CommentSaveDto commentSaveDto){
        log.info("查看评论列表：{}",commentSaveDto);
        return commentService.load(commentSaveDto);
    }

    /**
     * 评论点赞
     *
     * @param commentLikeDto
     * @return
     */
    @PostMapping("/like")
    public ResponseResult like(@RequestBody CommentLikeDto commentLikeDto){
        log.info("评论点赞信息为：{}",commentLikeDto);
        return commentService.like(commentLikeDto);
    }
}
